<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            list-style-type: none;
            margin: 0;
            padding: 0;
        }
        .tab {
            margin: 100px auto;
        }
        .tab_list {
            background-color: gainsboro;
            height: 39px;
            border-bottom: 1px solid #c81623;
        }

        .tab_list li {
            float: left;
            padding-left: 20px;
            padding-right: 20px;
            line-height: 39px;
            cursor: pointer;
        }
        .tab_list .current {
            background-color: #c81623;
            color: #fff;
        }

        .tab_list .normal {
            background-color: gainsboro;
            color: black;
        }

        .tab_item {
            /* display:改变元素的显示模式 */
            display: none;
        }
    </style>
</head>
<body>
    <div class="tab">
        <div class="tab_list">
            <ul>
                <li class="current">商品介绍</li>
                <li>规格与包装</li>
                <li>售后保障</li>
                <li>商品评价（1.1万+）</li>
            </ul>
        </div>
        <div class="tab_content">
            <div class="tab_item" style="display: block;">商品介绍模块内容</div>
            <div class="tab_item">规格与包装模块内容</div>
            <div class="tab_item">售后保障模块内容</div>
            <div class="tab_item">商品评价（50000）模块内容</div>
        </div>
    </div>
    <!-- js -->
    <script>
        //1.获取tab_lis中的所有li
        var tab_list = document.querySelector('.tab_list');
        var lis = tab_list.querySelectorAll('li');
        var tab_content = document.querySelector('.tab_content');
        var tab_items = tab_content.querySelectorAll('.tab_item');
        //2.给所有li添加点击手势
        for (var i = 0; i < lis.length; i++) {
            var liTemp = lis[i];
            liTemp.setAttribute('data-index',i);
            liTemp.onclick = function() {
                //1.清除样式
                for(var i = 0; i < lis.length; i++) {
                    lis[i].className = 'nomal';
                    tab_items[i].style.display = 'none';
                }
                //2.更改选中的样式
                this.className = 'current';
                var current_index = this.getAttribute('data-index');
                tab_items[current_index].style.display = 'block';
            }
        }
    </script>
</body>
</html>